#!/usr/bin/env python

'''Kikuhara Karin

@author Julot <andy.julot@gmail.com>
@since Sunday, February 3, 2013 11:18 AM'''

import argparse
from resource.string.app import argument as r

helps = {'f': 'hide all message',
         'v': 'print debug message'}

formatter_class = argparse.RawDescriptionHelpFormatter

parser = argparse.ArgumentParser(description=r.description, epilog=r.epilog,
                                 formatter_class=formatter_class, prog='Karin')

subParser = parser.add_subparsers()

# Stop Parser
stopParser = subParser.add_parser('stop', description=r.stopper.description,
                                  epilog=r.epilog, help=r.stopper.help,
                                  formatter_class=formatter_class)
stopParser.set_defaults(action='stop')

# Resume Parser
resumeParser = subParser.add_parser('resume', description=r.resumer.description,
                                    epilog=r.epilog, help=r.resumer.help,
                                    formatter_class=formatter_class)
resumeParser.set_defaults(action='resume')

# Modem Parser
modemParser = subParser.add_parser('modem', description=r.modem.description,
                                   epilog=r.epilog, help=r.modem.help,
                                   formatter_class=formatter_class)
modemSubParser = modemParser.add_subparsers()

# Modem Test Parser
modemTestParser = modemSubParser.add_parser('test',
        description=r.modem.tester.description,
        epilog=r.epilog,
        help=r.modem.tester.help,
        formatter_class=formatter_class)
modemTestParser.set_defaults(action='modem.test')
modemTestParser.add_argument('-v', '--verbose', action="store_true",
                             help=helps['v'])

# Modem Inspect Parser
modemInspectParser = modemSubParser.add_parser('inspect',
       description=r.modem.inspector.description,
       epilog=r.epilog, help=r.modem.inspector.help,
       formatter_class=formatter_class)
modemInspectParser.set_defaults(action='modem.inspect')
modemInspectParser.add_argument('-v', '--verbose', action="store_true",
                                help=helps['v'])

# SMS Parser
smsParser = subParser.add_parser('sms', description=r.sms.description,
                                 epilog=r.epilog, help=r.sms.help,
                                 formatter_class=formatter_class)
smsSubParser = smsParser.add_subparsers()

# SMS Voucher Parser
smsVoucherParser = smsSubParser.add_parser('voucher',
        description=r.sms.voucher.description,
        epilog=r.epilog, help=r.sms.voucher.help,
        formatter_class=formatter_class)
smsVoucherParser.set_defaults(action='sms.voucher')
smsVoucherParser.add_argument('-v', '--verbose', action="store_true",
                              help=helps['v'])

# SMS Save Parser
smsSaveParser = smsSubParser.add_parser('save',
                                        description=r.sms.saver.description,
                                        epilog=r.epilog, help=r.sms.saver.help,
                                        formatter_class=formatter_class)
smsSaveParser.set_defaults(action='sms.save')
smsSaveParser.add_argument('-f', '--silent', '--quiet', action="store_true",
                           help=helps['f'])
smsSaveParser.add_argument('-v', '--verbose', action="store_true",
                           help=helps['v'])

# SMS Decompile Parser
smsDecompileParser = smsSubParser.add_parser('decompile',
         description=r.sms.decompiler.description,
         epilog=r.epilog, help=r.sms.decompiler.help,
         formatter_class=formatter_class)
smsDecompileParser.set_defaults(action='sms.decompile')
smsDecompileParser.add_argument('-f', '--silent', '--quiet', action="store_true",
                                help=helps['f'])
smsDecompileParser.add_argument('-v', '--verbose', action="store_true",
                                help=helps['v'])

# SMS Upload Parser
smsUploadParser = smsSubParser.add_parser('upload',
        description=r.sms.uploader.description,
        epilog=r.epilog, help=r.sms.uploader.help,
        formatter_class=formatter_class)
smsUploadParser.set_defaults(action='sms.upload')
smsUploadParser.add_argument('-f', '--silent', '--quiet', action="store_true",
                             help=helps['f'])
smsUploadParser.add_argument('-v', '--verbose', action="store_true",
                             help=helps['v'])

# Camera Parser
cameraParser = subParser.add_parser('camera', description=r.camera.description,
                                    epilog=r.epilog, help=r.camera.help,
                                    formatter_class=formatter_class)
cameraSubParser = cameraParser.add_subparsers()

# Camera Setter Parser
cameraSetterParser = cameraSubParser.add_parser('set',
        description=r.camera.setter.description,
        epilog=r.epilog, help=r.camera.setter.help,
        formatter_class=formatter_class)
cameraSetterParser.set_defaults(action='camera.set')
cameraSetterParser.add_argument('-d', '--device', action="store", default=0,
                                help=r.camera.device, type=int)

# Camera Capture Parser
cameraCaptureParser = cameraSubParser.add_parser('capture',
        description=r.camera.captor.description,
        epilog=r.epilog, help=r.camera.captor.help,
        formatter_class=formatter_class)
cameraCaptureParser.set_defaults(action='camera.capture')
cameraCaptureParser.add_argument('-d', '--device', action="store", default=0,
                                 help=r.camera.device, type=int)
cameraCaptureParser.add_argument('-s', '--sequence', action="store", default=1,
                                 help=r.camera.sequence, type=int)
cameraCaptureParser.add_argument('--delay', action="store", default=5,
                                 help=r.camera.delay, type=int)
cameraCaptureParser.add_argument('--width', action="store", default=320,
                                 help=r.camera.width, type=int)
cameraCaptureParser.add_argument('--height', action="store", default=240,
                                 help=r.camera.height, type=int)
cameraCaptureParser.add_argument('-f', '--silent', '--quiet',
                                 action="store_true", help=helps['f'])
cameraCaptureParser.add_argument('-v', '--verbose', action="store_true",
                                 help=helps['v'])

# Camera Upload Parser
cameraUploadParser = cameraSubParser.add_parser('upload',
        description=r.camera.uploader.description,
        epilog=r.epilog, help=r.camera.uploader.help,
        formatter_class=formatter_class)
cameraUploadParser.set_defaults(action='camera.upload')
cameraUploadParser.add_argument('-s', '--sequence', action="store", default=1,
                                help=r.camera.sequence, type=int)
cameraUploadParser.add_argument('-u', '--url', action="store",
                                default='member.senkom.or.id',
                                help=r.camera.uploader.url)
cameraUploadParser.add_argument('-f', '--silent', '--quiet',
                                action="store_true", help=helps['f'])
cameraUploadParser.add_argument('-v', '--verbose', action="store_true",
                                help=helps['v'])


import _karin.sms, _karin.modem, _karin.camera

args = parser.parse_args()
action = args.action

# Complete
if action == 'stop':
    app = _karin.Stopper(args)
elif action == 'resume':
    app = _karin.Resumer(args)
elif action == 'modem.test':
    app = _karin.modem.Tester(args)
elif action == 'modem.inspect':
    app = _karin.modem.Inspector(args)
elif action == 'sms.voucher':
    app = _karin.sms.Voucher(args)
elif action == 'sms.save':
    app = _karin.sms.Saver(args)
elif action == 'sms.decompile':
    app = _karin.sms.Decompiler(args)
elif action == 'sms.upload':
    app = _karin.sms.Uploader(args)
elif action == 'camera.set':
    app = _karin.camera.Setter(args)
elif action == 'camera.capture':
    app = _karin.camera.Captor(args)
elif action == 'camera.upload':
    app = _karin.camera.Uploader(args)
    
# In progress


app.run()
del app